package com.cms.action;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import com.action.DefaultAction;
import com.cms.manager.CpInfoManager;
import com.cms.model.CpInfo;
import com.util.Util;

public class CpInfoAction extends DefaultAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Logger logger;
	private CpInfoManager manager;
	private String        type;
	private List<CpInfo> list;
	private CpInfo model;
	private String msg;
	
	public CpInfoAction()
	{
		logger = Logger.getLogger(this.getClass());
		manager = CpInfoManager.getInstance();
	}
	
	public String execute()
	{
		return SUCCESS;
	}

	public String list()
	{
		list = manager.getCpInfos();
		return SUCCESS;
	}
	
	public String show()
	{
		if(msg.equals("update"))
		{
			model = manager.getCpInfo(model.getId());
		}

		return SUCCESS;
	}
	
	public String save()
	{
		if(msg.equals("insert"))
		{
			model.setCreateDate(Util.dateToString(new Date()));
			model.setCreateUser(currentAdmin.getLoginName());
			if(manager.saveCpInfo("insert", model))
			{
				msg="CP管理：添加CP成功！！";
			}
			else
			{
				msg="CP管理：对不起，添加CP可能存在问题，请稍候重试一下！！";
			}
		}
		else if(msg.equals("update"))
		{
			if(manager.saveCpInfo("update", model))
			{
				msg="CP管理：更新CP成功！！";
			}
			else
			{
				msg="CP管理：对不起，更新CP可能存在问题，请稍候重试一下！！";
			}
		}
		else if(msg.equals("del"))
		{
			if(manager.saveCpInfo("delete", model))
			{
				msg="CP管理：删除CP成功！！";
			}
			else
			{
				msg="CP管理：对不起，删除CP可能存在问题，请稍候重试一下！！";
			}
		}
		return SUCCESS;
	}
	
	
	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<CpInfo> getList() {
		return list;
	}

	public void setList(List<CpInfo> list) {
		this.list = list;
	}

	public CpInfo getModel() {
		return model;
	}

	public void setModel(CpInfo model) {
		this.model = model;
	}

	
	
	
}
